package com.xgll.modules.api.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.xgll.common.annotation.IgnoreAuth;
import com.xgll.common.utils.R;
import com.xgll.modules.api.entity.Points;
import com.xgll.modules.api.entity.UserVo;
import com.xgll.modules.api.service.ApiPointsService;

@RestController
@RequestMapping("/api/point")
public class ApiPointsController {
	@Autowired
	private ApiPointsService aps;

	@RequestMapping("list")
	@IgnoreAuth
    public Object list(HttpSession session) {
		UserVo user = (UserVo)session.getAttribute("loginUser");
        Map param = new HashMap();
        param.put("usr_id", user.getUserId());
        List<Points> points = aps.queryList(param);
        return R.ok().put("points", points);
    }
	
	@RequestMapping("/points/{uid}")
	@IgnoreAuth
	public R getpoints(@PathVariable("uid") Integer usr_id) {

		return R.ok().put("points", aps.queryObject(usr_id));
	}

	@RequestMapping("/pointsG/{uid}")
	@IgnoreAuth
	public R getgainpoints(@PathVariable("uid") Integer usr_id) {
		return R.ok().put("gain", aps.findgain(usr_id));
	}

	@RequestMapping("/pointsE/{uid}")
	@IgnoreAuth
	public R getexpendpoints(@PathVariable("uid") Integer usr_id) {
		return R.ok().put("expend", aps.findexpend(usr_id));
	}
	// 求获得的总积分

	// 求花费的总积分

	@RequestMapping("/point/{uid}")
	@IgnoreAuth
	public R points(@PathVariable("uid") Integer usr_id) {
		List<List<Map<String, Object>>> ls = new ArrayList<>();
		ls.add(aps.queryObject(usr_id));
		ls.add(aps.findgain(usr_id));
		ls.add(aps.findexpend(usr_id));
		return R.ok().put("a", ls);
	}

	@RequestMapping("modifyPoints")
	@IgnoreAuth
	public List<Points> getPoints(@RequestParam("uid") Integer uid) {
		return aps.getPointsByuid(uid);
	}
}
